#include <cstdio>
#include <cstring>

int n, f[ 1011 ][ 1011 ];
char s[ 1011 ][ 1011 ];

void init( )
{
    int i, j, k;;
    for ( i = 0; i < n; i++ )
        scanf("%s", s[ i ]);
    memset( f, 0, sizeof( f ) );
    for ( i = 0; i < n; i++ )
        for ( j = 0; j < n; j++ )
            for ( k = 0; i + k < n && k <= j; k++ )
                if ( s[ i + k ][ j ] == s[ i ][ j - k ] )
                    f[ i ][ j ]++;
                else
                    break;
}

bool check( int q, int flag, int p )
{
    int i, j, t;
    if ( flag )
    {
        t = q;
        for ( i = 0; i <= p; i++ )
        {
            j = p - i;
            if ( f[ i ][ j ] >= t )
                t--;
            else
                t = q;
            if ( !t )
                return true;
        }
    }
    else
    {
        t = q;
        for ( i = p; i < n; i++ )
        {
            j = n - ( i - p ) - 1;
            if ( f[ i ][ j ] >= t )
                t--;
            else
                t = q;
            if ( !t )
                return true;
        }
    }
    return false;
}

void work( )
{
    int i, ans = 0, l, r, m;
    for ( i = 0; i < n; i++ )
    {
        l = 1; r = n;
        while ( l < r )
        {
            m = ( l + r ) / 2;
            if ( !check( m, 1, i ) )
                r = m - 1;
            else
                l = m + 1;
        }
        if ( check( l + 1, 1, i ) && ans < l + 1 )
            ans = l + 1;
        else
            if ( check( l, 1, i ) && ans < l )
                ans = l;
            else
                if ( ans < l - 1 )
                    ans = l - 1;
    }
    for ( i = 1; i < n; i++ )
    {
        l = 1; r = n;
        while ( l < r )
        {
            m = ( l + r ) / 2;
            if ( !check( m, 0, i ) )
                r = m - 1;
            else
                l = m + 1;
        }
        if ( check( l + 1, 0, i ) && ans < l + 1 )
            ans = l + 1;
        else
            if ( check( l, 0, i ) && ans < l )
                ans = l;
            else
                if ( ans < l - 1 )
                    ans = l - 1;
    }
    printf("%d\n", ans);
}

int main( )
{
    int i, j, k;
    while ( scanf("%d", &n) && n )
    {
        init( );
        work( );
    }
    return 0;
}
